package com.syswin.lhztest.configuration;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author:lhz
 * @date:2018/11/30 17:36
 */
public class ElasticsearchConfigTest {

	public static TransportClient esClient(){
		Settings esSettings = Settings.builder()
						.put("cluster.name", "elasticsearch")
						.put("client.transport.sniff", true)
						.build();
		TransportClient client = null;
		try {
			client = new PreBuiltTransportClient(esSettings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.92.128"), 9300));
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
		System.out.println("ElasticsearchClient 连接成功");
		return client;
	}

	public static void main(String[] args) {
		ElasticsearchConfigTest.esClient();
	}

}
